﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InformationSystem.BLL.Core.Service;
using InformationSystem.BLL.Core.Model;
using InformationSystem.BLL.Core.Dao.Impl;
using Ext.Net;

namespace InformationSystem.WebSite.Module.StuMgr
{
    public partial class ClassMgr : BasePage
    {
        public ICollegeService CollegeService { get; set; }
        protected LoginUser user;
        protected void Page_Load(object sender, EventArgs e)
        {
            user = (LoginUser)Session["LoginUser"];
            if (!X.IsAjaxRequest && !IsPostBack)
            {
                IList<ClassInfo> classList = CollegeService.GetClassInfoByAss(user);
                classListStore.DataSource = classList;
                classListStore.DataBind();
            }
        }

        protected void BeforeRecordDeleted(object sender, BeforeRecordDeletedEventArgs e)
        {
            ClassInfo classinfo = e.Object<ClassInfo>();
            if (classinfo.ClassID == string.Empty || classinfo.ClassName == string.Empty) return;
            bool result=  CollegeService.DeleteClassInfoByID(classinfo.ClassID,user);
            if (result)
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "删除成功！"
                });
            }
            else
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "你没有权限删除该班级信息！"
                });
            }
        }
        protected void BeforeRecordInserted(object sender, BeforeRecordInsertedEventArgs e)
        {
            ClassInfo classinfo = e.Object<ClassInfo>();
            if (classinfo.ClassID == string.Empty || classinfo.ClassName == string.Empty) return;
            classinfo.CreateDateTime = DateTime.Now;
            bool result = CollegeService.CreateClassInfo(classinfo,user);
            if (result)
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "创建成功！"
                });
            }
            else
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "你没有权限创建该班级信息！"
                });
            }

        }
        protected void BeforeRecordUpdated(object sender, BeforeRecordUpdatedEventArgs e)
        {
            ClassInfo classinfo = e.Object<ClassInfo>();
            if (classinfo.ClassID == string.Empty || classinfo.ClassName == string.Empty) return;
            bool result = CollegeService.UpdateClassInfo(classinfo,user);
            if (result)
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "修改成功！"
                });
            }
            else
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "你没有权限修改该班级信息！"
                });
            }
        }
        protected void AfterStoreChanged(object sender, AfterStoreChangedEventArgs e)
        {
            IList<ClassInfo> classList = CollegeService.GetClassInfoByAss(user);
            classListStore.DataSource = classList;
            classListStore.DataBind();
            this.classListStore.RefreshAfterSaving = RefreshAfterSavingMode.Always;
        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            IList<ClassInfo> classList = CollegeService.GetClassInfoByAss(user);
            classListStore.DataSource = classList;
            classListStore.DataBind();
        }
        protected override bool CommitPermissionCheck()
        {
            throw new NotImplementedException();
        }
    }
}